@use 'sass:map';
@use '../uni';

// 颜色映射
$color-map: (
  'primary': uni.$uni-color-primary,
  'success': uni.$uni-color-success,
  'warning': uni.$uni-color-warning,
  'error': uni.$uni-color-error,
  'text': uni.$uni-text-color,
  'text-inverse': uni.$uni-text-color-inverse,
  'text-grey': uni.$uni-text-color-grey,
  'text-placeholder': uni.$uni-text-color-placeholder,
  'text-disable': uni.$uni-text-color-disable,
  'white': uni.$uni-bg-color,
  'grey': uni.$uni-bg-color-grey,
  'hover': uni.$uni-bg-color-hover
);

// 文本颜色
@each $key, $value in $color-map {
  .text-#{$key} {
    color: $value;
  }
}

// 背景色
@each $key, $value in $color-map {
  .bg-#{$key} {
    background-color: $value;
  }
}

// 文本对齐
@each $align in (left, center, right) {
  .text-#{$align} {
    text-align: $align;
  }
}

// 字体大小
.font-sm { font-size: uni.$uni-font-size-sm; }
.font-base { font-size: uni.$uni-font-size-base; }
.font-lg { font-size: uni.$uni-font-size-lg; }

// 边距映射
$spacing-map: (
  'sm': (
    'row': uni.$uni-spacing-row-sm,
    'col': uni.$uni-spacing-col-sm
  ),
  'base': (
    'row': uni.$uni-spacing-row-base,
    'col': uni.$uni-spacing-col-base
  ),
  'lg': (
    'row': uni.$uni-spacing-row-lg,
    'col': uni.$uni-spacing-col-lg
  )
);

// 生成 margin 工具类
@each $size, $spacings in $spacing-map {
  .m-#{$size} { margin: map.get($spacings, 'row'); }
  .mx-#{$size} {
    margin-left: map.get($spacings, 'row');
    margin-right: map.get($spacings, 'row');
  }
  .my-#{$size} {
    margin-top: map.get($spacings, 'col');
    margin-bottom: map.get($spacings, 'col');
  }
  .mt-#{$size} { margin-top: map.get($spacings, 'col'); }
  .mr-#{$size} { margin-right: map.get($spacings, 'row'); }
  .mb-#{$size} { margin-bottom: map.get($spacings, 'col'); }
  .ml-#{$size} { margin-left: map.get($spacings, 'row'); }
}

// 生成 padding 工具类
@each $size, $spacings in $spacing-map {
  .p-#{$size} { padding: map.get($spacings, 'row'); }
  .px-#{$size} {
    padding-left: map.get($spacings, 'row');
    padding-right: map.get($spacings, 'row');
  }
  .py-#{$size} {
    padding-top: map.get($spacings, 'col');
    padding-bottom: map.get($spacings, 'col');
  }
  .pt-#{$size} { padding-top: map.get($spacings, 'col'); }
  .pr-#{$size} { padding-right: map.get($spacings, 'row'); }
  .pb-#{$size} { padding-bottom: map.get($spacings, 'col'); }
  .pl-#{$size} { padding-left: map.get($spacings, 'row'); }
}

// 圆角
.rounded-sm { border-radius: uni.$uni-border-radius-sm; }
.rounded { border-radius: uni.$uni-border-radius-base; }
.rounded-lg { border-radius: uni.$uni-border-radius-lg; }
.rounded-full { border-radius: uni.$uni-border-radius-circle; }

// Flex 布局
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-1 { flex: 1; }
.flex-auto { flex: auto; }
.flex-none { flex: none; }

// Flex 方向
.flex-row { flex-direction: row; }
.flex-row-reverse { flex-direction: row-reverse; }
.flex-col { flex-direction: column; }
.flex-col-reverse { flex-direction: column-reverse; }

.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }
.flex-wrap-reverse { flex-wrap: wrap-reverse; }

// Justify Content
.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.justify-evenly { justify-content: space-evenly; }

// Align Items
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.items-stretch { align-items: stretch; }

// Align Self
.self-auto { align-self: auto; }
.self-start { align-self: flex-start; }
.self-end { align-self: flex-end; }
.self-center { align-self: center; }
.self-baseline { align-self: baseline; }
.self-stretch { align-self: stretch; }

// Align Content
.content-start { align-content: flex-start; }
.content-end { align-content: flex-end; }
.content-center { align-content: center; }
.content-between { align-content: space-between; }
.content-around { align-content: space-around; }
.content-stretch { align-content: stretch; }